package com.example.esp8266.Main.Main_Fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.example.esp8266.R;
import com.example.esp8266.TcpService.Tcp_Connect;


public class ExpandFragment extends Fragment
        implements View.OnClickListener{

    private View root;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @SuppressLint("SetTextI18n")
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        root = inflater.inflate(R.layout.expand_fragment, container, false);

        Button service_start = root.findViewById(R.id.service_start_btn);
        service_start.setOnClickListener(this);

        Button service_stop = root.findViewById(R.id.service_stop_btn);
        service_stop.setOnClickListener(this);

        return root;
    }

    @Override//调用OnClickListener接口处理各种单击事件
    public void onClick(View v) {
        if (v.getId() == R.id.service_start_btn) {
            // 创建一个Intent来启动服务
            Intent serviceIntent = new Intent(requireActivity(), Tcp_Connect.class);
            // 启动服务
            requireActivity().startService(serviceIntent);
        } else if (v.getId() == R.id.service_stop_btn) {
            // 创建一个Intent来停止服务
            Intent serviceIntent = new Intent(requireActivity(), Tcp_Connect.class);
            // 停止服务
            requireActivity().stopService(serviceIntent);
        }
    }
}